package com.itheima.reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @author Anomaly
 * @date 2023/2/11 21:18
 */
public class ClassDemo {
    public static void main(String[] args) throws Exception {
        System.out.println(Class.forName("com.itheima.reflect.Student"));
        System.out.println(Student.class);
        Student s = new Student();
        System.out.println(s.getClass());

        System.out.println("======================");

        Constructor<Student> c = Student.class.getDeclaredConstructor(String.class, int.class);
        System.out.println(c.getName());
        Student s2 = c.newInstance("root", 155);
        System.out.println(s2);

        System.out.println("======================");

        Field f = Student.class.getDeclaredField("name");
        f.setAccessible(true);
        Student s3 = new Student();
        f.set(s3, "admin");
        System.out.println(s3);
        System.out.println(f.get(s3));

        System.out.println("======================");

        Method m = Student.class.getDeclaredMethod("test", String.class, int.class);
        System.out.println(m);
        Student s4 = new Student("只因", 20);
        Object o = m.invoke(s4, "呵呵呵", 10);
        System.out.println(o);

    }
}
